// pages/mine/baby/add.js
const $api = require("../../../api/mine").API
<<<<<<< HEAD
const $upload= require("../../../api/upload").API

=======
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
var util= require("../../../utils/util");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    fileList:[],
    false:false,
    true:true,
    show:false,
    child_birthday:"",//孩子生日
    member_id:'',//用户id
    child_name:'',//	孩子名称
    circle_files:'',//文件列表
    parent_role:'',//关系id 家长端必填
    child_sex:'',//性别1男2女3保密
    nation:'',//民族
    firscontacts:'',//第一联系人电话
    firscontacts_name:'',	//第一联系人姓名
    timeShow:false,
<<<<<<< HEAD
    child_sex:"1",
=======
    actions: [
      {
        name: '男',
        index:1
      },
      {
        name: '女',
        index:2
      }
    ],
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
  currentDate: new Date().getTime(),
  formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      }
      return value;
    }
  },
  changeBirthday(){
    var t = this
    t.setData({
      timeShow:true
    })
  },
  setsex(e){
    var t = this
    t.setData({
      show:true,
    })
  },
 
  changeTime(e){
    console.log(e)
    var times =  util.js_date_time(e.detail/1000)
    var t = this
    t.setData({
      timeShow:false,
      child_birthday:times
    })
  },
  onSelect(event) {
    console.log(event.detail);
    console.log(1)
    var t = this
    t.setData({
      child_sex:event.detail.index
    })
  },
  closetime(e){
    var t = this
    t.setData({
      show:false,
      timeShow:false,
    })
  },
  // onInput(event) {
  //   this.setData({
  //     currentDate: event.detail,
  //   });
  // },
  afterRead(e){
    var t =this
    console.log(33333)
    wx.chooseImage({
      count: 1,	// 默认为9
      sizeType: ['original', 'compressed'],	// 指定原图或者压缩图
      sourceType: ['album', 'camera'],	// 指定图片来源
      success: function(res) {
        var tempFilePaths = [{
          url:res.tempFilePaths[0],
          name:'图片'
        }]
        t.setData({
          fileList:tempFilePaths
        })
        console.log(tempFilePaths)
      }
    })
  },
  //获取姓名
  getchild_name(e){
    var t = this
    t.setData({
      child_name:e.detail
    })
  },
<<<<<<< HEAD
  // 获取角色
  getparent_role(e){
    var t = this
    t.setData({
      parent_role:e.detail
    })
  },
  // 民族
  getnation(e){
    var t = this
    t.setData({
      nation:e.detail
    })
  },
  // 第一联系人
  getfirscontacts_name(e){
    var t = this
    t.setData({
      firscontacts_name:e.detail
    })
  },
  // 联系电话
  getfirscontacts(e){
    var t = this
    t.setData({
      firscontacts:e.detail
    })
  },
  onChangesex(e){
    var t= this
    t.setData({
      child_sex:e.detail
    })
  },
  delimg(){
    var t = this
    t.setData({
      fileList:[]
    })
  },
  saveChild(){
    var t = this
    $upload.uploadQiniu(t.data.fileList).then(res=>{
      var data = {
        member_id:wx.getStorageSync('user').member_id,
        child_name:t.data.child_name,
        child_birthday:t.data.child_birthday,
        circle_files:res[0],
        parent_role:wx.getStorageSync('user').parental_id,
        parent_role_name:wx.getStorageSync('user').memberi_nick,
        child_sex:t.data.child_sex,
        nation:t.data.nation,
        firscontacts:t.data.firscontacts,
        firscontacts_name:t.data.firscontacts_name
      }
      $api.saveChild(data).then(res=>{
        console.log(res)
      })
    })
  },
=======
  //获取姓名
  // getchild_name(e){
  //   var t = this
  //   t.setData({
  //     child_name:e.detail
  //   })
  // },
>>>>>>> 1c9ce1fdc7fcbf1a028b999eb3cd07f698a8a329
})